import request from "@/api/request.js";

//get all classes
export const getAllClassService = () => {
  return request.get("/api-self/users/class/getClasses");
};

//get class`s members
export const getClassMemberService = dataObj => {
  const params = new URLSearchParams();
  for (let key in dataObj) {
    params.append(key, dataObj[key]);
  }
  let queryString = params.toString();
  let url = `/api-self/users/class/getClassMembers?${queryString}`;
  return request.get(url);
};

//add classes
export const addClassService = dataObj => {
  const params = new URLSearchParams();
  for (let key in dataObj) {
    params.append(key, dataObj[key]);
  }
  return request.post("/api-self/users/class/addClass", params);
};

//add classe`s member
export const addClassMemberService = dataObj => {
  return request.post("/api-self/users/class/addUser", dataObj);
};

//del class
export const delClassService = dataObj => {
  const params = new URLSearchParams();
  for (let key in dataObj) {
    params.append(key, dataObj[key]);
  }
  let queryString = params.toString();
  let url = `/api-self/users/class/deleteClass?${queryString}`;
  return request.delete(url);
};

//del class`s member
export const delClassMemberService = dataObj => {
  const params = new URLSearchParams();
  for (let key in dataObj) {
    params.append(key, dataObj[key]);
  }
  let queryString = params.toString();
  let url = `/api-self/users/class/deleteUser?${queryString}`;
  return request.delete(url);
};
